package com.qing.array;

/**
 * 操作数组
 */
public class OperationArray {
    static int[] nums = {1, 2, 4, 3};

    public static void main(String[] args) {
        getMaxNum();
        reverseNums();
    }

    //获取最大值
    public static void getMaxNum() {
        int maxNum = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > maxNum) {
                maxNum = nums[i];
            }
        }
        System.out.println("max = " + maxNum);
    }

    //反转数组
    public static void reverseNums() {
        int[] reverseNums = new int[nums.length];

        // 方法1
        int k = 0;
        for (int i = nums.length - 1; i >= 0; i--) {
            reverseNums[k] = nums[i];
            k++;
        }

        //方法2
        for (int i = nums.length - 1, j = 0; i >= 0; i--, j++) {
            reverseNums[j] = nums[i];
        }

        if (reverseNums.length != 0) {
            System.out.print("反转数组后值为：");
            for (int reverseNum : reverseNums) {
                System.out.print(reverseNum + "\t");
            }
        }
    }
}
